﻿#pragma once
#include "Singleton.h"
#include <QString>
#include <QFile>
#include <QTextStream>
#include <QDateTime>
#include <QDebug>
class Logger :public Singleton<Logger>
{
    friend class Singleton<Logger>;
public:
    void LogInfo(const QString& message);
    void LogWarning(const QString& message);
    void LogError(const QString& message);
    void LogCriticalError(const QString& message);
private:
    Logger() {
        m_file.setFileName("spyderlog.txt");
        if (!m_file.open(QIODevice::WriteOnly | QIODevice::Append | QIODevice::Text)) {
            qWarning() << "Cannot open logger file";
        }

    }
    void Log(const QString& level, const QString& message) {
        if (m_file.isOpen() && m_file.isWritable()) {
            QTextStream logstream(&m_file);
            logstream << QDateTime::currentDateTime().toString("yyyy-mm-dd hh:mm:ss") << " ";
            logstream << level << ": " << message << endl;
        }
        else {
            qWarning() << "Cannot write to logger file";
        }
        QTextStream(stdout) << level << ": " << message << endl;
    }
private:
    QFile m_file;
};

